package com.woniuxy.house.service.serviceimpl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.woniuxy.house.entity.PageBean;
import com.woniuxy.house.entity.Source;
import com.woniuxy.house.mapper.SourceMapper;
import com.woniuxy.house.service.ApartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 首页公寓功能的接口的实现类
 */
@Service("apartmentServiceImpl")
public class ApartmentServiceImpl implements ApartmentService {
    @Autowired
   private SourceMapper sourceMapper;
    @Override
    public PageBean<Source> getByPage(Source source, int page) {
       source.setHouseStyle("公寓");
        //根据条件页码分页大小将PageBean中的属性一次设置
        PageBean<Source> pageBean = new PageBean<>();
        pageBean.setPageSzie(4);//分页大小
        pageBean.setCurrPage(page);    //设置当前页数
        Page p = PageHelper.startPage(pageBean.getCurrPage(), pageBean.getPageSzie());
        List<Source> list = sourceMapper.getSourceListByCondition(source);
        pageBean.setTotalNums((int) p.getTotal());//设置总数量
        pageBean.setTotalPage(p.getPages());
        pageBean.setData(list);//设置当前页数的数据
        pageBean.setCurrpageSzie(pageBean.getData().size());//当前页数据数量
        return pageBean;
    }
}
